package com.modules.controller.sys;


import com.common.controller.BaseController;
import com.common.log.LogData;
import com.common.vo.Result;
import com.modules.entity.sys.DeptEntity;
import com.modules.service.sys.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 部门
 * @author yyq
 *
 */
@RestController
@RequestMapping("/sys/dept")
public class DeptController extends BaseController<DeptEntity>{

	@Autowired
	private DeptService service;


	/**
	 * 查询
	 * @param entity
	 * @return
	 */
	@PostMapping("/select")
	public Result<?> select(DeptEntity entity){
		entity.setOid(entity.getOid() == null ? getUser().getLastOid() : entity.getOid());
		return service.select(entity);
	}

	@PostMapping("/selectTree2")
	public Result<?> selectTree2(DeptEntity entity){
		entity.setOid(entity.getOid() == null ? getUser().getLastOid() : entity.getOid());
		return service.select(entity);
	}

	/**
	 * 查询
	 * @param entity
	 * @return
	 */
	@PostMapping("/selectOne")
	public Result<?> selectOne(DeptEntity entity){
		return service.selectOne(entity);
	}

	/**
	 * 保存
	 * @param entity
	 * @return
	 */
	@LogData(module = "部门管理", remarks = "保存")
	@PostMapping("/save")
	public Result<?> save(DeptEntity entity){
		return service.save(entity);
	}
	
	/**
	 * 删除
	 * @return
	 */
	@LogData(module = "部门管理", remarks = "删除单个")
	@DeleteMapping("/delete")
	public Result<?> delete(DeptEntity entity){
		return service.delete(entity.getDid());
	}

	/**
	 * 获取当前组的所有
	 * @param entity
	 * @return
	 */
	@PostMapping("/selectBranch")
	public Result<?> selectBranch(DeptEntity entity){
		entity.setOid(entity.getOid() == null ? getUser().getLastOid() : entity.getOid());
		return service.selectBranch(entity);
	}

	/**
	 * 获取当前组的所有
	 * @param entity
	 * @return
	 */
	@PostMapping("/selectTop")
	public Result<?> selectTop(DeptEntity entity){
		entity.setOid(entity.getOid() == null ? getUser().getLastOid() : entity.getOid());
		return service.selectTop(entity);
	}



}
